package com.example.safeassistan.risk.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import com.example.safeassistan.R;
import com.example.safeassistan.base.BaseActivity;

public class ActivityInstructionDetail  extends BaseActivity  {
    private String title,content;
    private WebView webView;

    public static void actionStart(Context context,String title,String content) {
        Intent intent = new Intent(context, ActivityInstructionDetail.class);
        intent.putExtra("content",content);
        intent.putExtra("title",title);
        context.startActivity(intent);
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_instruction_detail;
    }

    @Override
    protected void initView() {
        content=getIntent().getStringExtra("content");
        title=getIntent().getStringExtra("title");
        setTitleText(title);
        webView=findViewById(R.id.webView);
        StringBuilder sb = new StringBuilder();
        sb.append(getHtmlData(content));
        webView.loadDataWithBaseURL(null,sb.toString(),"text/html", "utf-8", null);
    }

    /**
     * 富文本适配
     */
    private String getHtmlData(String bodyHTML) {
        String head = "<head>"
                + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> "
                + "<style>img{max-width: 100%; width:auto; height:auto;}</style>"
                + "</head>";
        return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
    }

    @Override
    protected void initData() { }

    /**
     * 获取要使用的标题栏样式(此函数由子类重写)
     * @return
     */
    @Override
    protected int getTitleBarType() {
        return 0;
    }
}